<!DOCTYPE html>
<html lang="en">

<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css/style.css" rel="stylesheet">
</head>

<body>
    <script>
        let m = 37
        let n = 1111

        let min = m > n ? n : m
        let max = m <= n ? n : m
        let arr = [];
        for (let i = 2; i <= Math.floor(min / 2); i++) {
            if (min % i === 0) arr.push(i);
        }
        let arr2 = []
        for (let i = 2; i <= Math.floor(max / 2); i++) {
            if (max % i === 0) arr2.push(i);
        }
        //每个数的因子
        console.log(arr, arr2)
        arr.push(1)
        arr.push(min)
        arr2.push(1)
        arr2.push(max)
        let res = 0
        let res1 = 0
        let res2 = 0
        arr.sort((a, b) => b - a)
        arr2.sort((a, b) => b - a)
        for (let i = 0; i < arr2.length; i++) {
            if (myInclude(min.toString(), arr2[i])) {
                res1 = min.toString().length - arr2[i].toString().length
                break
            }
        }
        for (let i = 0; i < arr.length; i++) {
            if (myInclude(max.toString(), arr[i])) {
                res2 = max.toString().length - arr[i].toString().length
                break
            }
        }
        res = Math.min(res1, res2)

        console.log(res)
        function myInclude(str1, str2) {
            //str1中是否包含str2
            let tmpArr = str1.split("");
            for (let i = 0; i < str2.length; i++) {
                if (tmpArr.includes(str2[i])) {
                    tmpArr.splice(tmpArr.indexOf(str2[i]), 1)
                } else {
                    return false
                }
            }
            return true
        }
    </script>
</body>

</html>